<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title> 
    <style> 

    </style>
</head>
<body>
    <input type="text" id="text" />
    <button id='button'>点我</button>
    <script> 
        document.querySelector('#button').addEventListener('click',function(){
            let input = document.querySelector('#text').value
            testPromise(input%2==0) 
        })
        
        function testPromise(flag){ 
            let p = new Promise((resolve,reject) =>{ 
                if(flag){
                    resolve('resolve success !')
                }else{
                    reject('reject error !')
                }
            })
            p.then(res => {
                    console.log(res)
                },error =>{
                    console.log(error)
                }).catch(e =>{
                    console.log(e)
                })
        }


        // var p1 = new Promise(function (resolve, reject) {
        // setTimeout(() => resolve('success'), 3000)
        // }) 
        
        var p1 = new Promise(function (resolve, reject) {
        setTimeout(() => reject('fail'), 3000)
        })

        var p2 = new Promise(function (resolve, reject) {
        setTimeout(() => resolve(p1), 1000)
        })

        p2
        .then(result => console.info(result))
        .catch(error => console.error(error))
    </script>
</body>
</html>